package cn.com.utt.unms.mapper;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import cn.com.utt.unms.pojo.Ssid;

@Mapper
public interface SsidMapper {
	
	@Select("select * from ssid where wireless_id=#{wirelessId}")
	Ssid querySsidsByWireless(@Param("wirelessId")long wirelessId);
	
	@Select({"<script>",
	    "select * ", 
	    "FROM ssid",
	    "WHERE ", 
	    "wireless_id IN", 
	      "<foreach item='item' index='index' collection='wirelessIds'",
	        "open='(' separator=',' close=')'>",
	        "#{item}",
	      "</foreach>",
	"</script>"})
	List<Ssid> querySsidsByWirelesses(@Param("wirelessIds")List<Long> wirelessIds);
	
	@Delete({"<script>",
	    "delete ", 
	    "FROM ssid",
	    "WHERE ", 
	    "wireless_id IN", 
	      "<foreach item='item' index='index' collection='wirelessIds'",
	        "open='(' separator=',' close=')'>",
	        "#{item}",
	      "</foreach>",
	"</script>"})
	void deleteSsidByWirelesses(@Param("wirelessIds")Collection<Long> wirelessIds);
	
	@Insert("insert into ssid(wireless_id,`index`,`name`,encode,hide,bssid,vid,mode,rxrate,txrate,portal_auth,sec_type,wep_encryption_mode,wep_key_format,wep_key_index,wep_encryption_level,wep_key_passphrase,wpa_version,wpa_encryption_mode,wpakey,wpakey_update_interval,radius_server,radius_port,radius_key,main_uses,broadcast_filter,dtim_interval,multicast_op,dynamic_op,dmo_threshold,g24_min_rate,g24_max_rate,g5_min_rate,g5_max_rate,empty_port_op,per_wireless_op,bg_vmm_share,eff_vmm_share,video_vmm_share,voice_vmm_share,content_filter,freq_channel,inactive_timeout,max_conn,probe_req_limit,auto_update,client_isolation) "
			+ "values(#{wirelessId},#{index},#{name},#{encode},#{hide},#{bssid},#{vid},"
			+ "#{mode},#{rxrate},#{txrate},#{portalAuth},#{secType},#{wepEncryptionMode},#{wepKeyFormat},#{wepKeyIndex},#{wepEncryptionLevel},#{wepKeyPassphrase},#{wpaVersion},#{wpaEncryptionMode},"
			+ "#{wpakey},#{wpakeyUpdateInterval},#{radiusServer},#{radiusPort},#{radiusKey},#{mainUses},#{broadcastFilter},#{dtimInterval},#{multicastOp},#{dynamicOp},#{dmoThreshold},#{g24MinRate},#{g24MaxRate},#{g5MinRate},#{g5MaxRate},#{emptyPortOp},#{perWirelessOp},"
			+ "#{bgVmmShare},#{effVmmShare},#{videoVmmShare},#{voiceVmmShare},#{contentFilter},#{freqChannel},#{inactiveTimeout},#{maxConn},#{probeReqLimit},#{autoUpdate},#{clientIsolation})")
	void save(Ssid ssid);
	
	@Update("update ssid set mode=#{mode},wireless_id=#{wirelessId},`index`=#{index},`name`=#{name},encode=#{encode},hide=#{hide},vid=#{vid},rxrate=#{rxrate},txrate=#{txrate},portal_auth=#{portalAuth},sec_type=#{secType},wep_encryption_mode=#{wepEncryptionMode},wep_key_format=#{wepKeyFormat},wep_key_index=#{wepKeyIndex},wep_encryption_level=#{wepEncryptionLevel},wep_key_passphrase=#{wepKeyPassphrase},wpa_version=#{wpaVersion},wpa_encryption_mode=#{wpaEncryptionMode},wpakey=#{wpakey},"
			+ "wpakey_update_interval=#{wpakeyUpdateInterval},radius_server=#{radiusServer},radius_port=#{radiusPort},radius_key=#{radiusKey},main_uses=#{mainUses},broadcast_filter=#{broadcastFilter},dtim_interval=#{dtimInterval},multicast_op=#{multicastOp},dynamic_op=#{dynamicOp},dmo_threshold=#{dmoThreshold},g24_min_rate=#{g24MinRate},g24_max_rate=#{g24MaxRate},g5_min_rate=#{g5MinRate},g5_max_rate=#{g5MaxRate},empty_port_op=#{emptyPortOp},per_wireless_op=#{perWirelessOp},bg_vmm_share=#{bgVmmShare},"
			+ "eff_vmm_share=#{effVmmShare},video_vmm_share=#{videoVmmShare},voice_vmm_share=#{voiceVmmShare},content_filter=#{contentFilter},freq_channel=#{freqChannel},inactive_timeout=#{inactiveTimeout},max_conn=#{maxConn},probe_req_limit=#{probeReqLimit},auto_update=#{autoUpdate},client_isolation=#{clientIsolation} where id=#{id}")
	void update(Ssid ssid);
	
	@Delete("delete from ssid where id=#{id}")
	void delete(@Param("id")long id);
	
	@Select("select * from ssid where id=#{id}")
	Ssid findById(@Param("id")long id);
	
	@Select("select ssid.`name` from ssid where wireless_id in (select wireless_id from group_wireless where group_id =(select group_id from device where id=#{deviceId}))")
	List<String> querySsidListsById(@Param("deviceId")long deviceId);
	
	@Select({"<script>",
	    "select vid,count(vid) as total ", 
	    "FROM ssid",
	    "WHERE ", 
	    "wireless_id IN", 
	      "<foreach item='item' index='index' collection='wirelessIds'",
	        "open='(' separator=',' close=')'>",
	        "#{item}",
	      "</foreach>",
	      "group by vid",
	"</script>"})
	List<Map<String,Object>> checkVid(@Param("wirelessIds")Collection<Long> wirelessIds);
}
